﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace InSys.Documents
{
    public partial class FormPersonDepartment : Form
    {
        private MapTestLinqDataContext db = new MapTestLinqDataContext(Properties.Settings.Default.testlinqConnectionString);
        public FormPersonDepartment()
        {
            InitializeComponent();
            var queryPerson = from item in db.persons select item;
            personBindingSource.DataSource = queryPerson.ToList();
            var queryDepartment = from item in db.departments select item;
            departmentBindingSource.DataSource = queryDepartment.ToList();
            var queryPersonDepartment = from item in db.person_departments orderby item.date descending select item;
            person_departmentBindingSource.DataSource = queryPersonDepartment;
        }

        private void person_departmentDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                this.Validate();
                db.SubmitChanges();
            }
            catch
            {
                MessageBox.Show("Ошибка");
            }
        }
    }
}
